package custom;

import java.awt.geom.Ellipse2D;
import java.util.LinkedList;
import java.util.List;

public class Ball implements IBouncingBallsModel {

	private final double areaWidth;
	private final double areaHeight;

	private double x, y, vx, vy, r, gravity = -0.03;
	

	public Ball(double width, double height) {
		this.areaWidth = width;
		this.areaHeight = height;
		x = 1;
		y = 1;
		vx = 3;
		vy = 1.5;
		r = 1;
	}
	
	public Ball(double width, double height, double newX, double newY, double radius) {
		this(width, height);
		x = newX;
		y = newY;
		r = radius;
	}

	@Override
	public void tick(double deltaT) {
		if (x > areaWidth - r && vx > 0) {
			vx *= -1;
		}
		if (x < r && vx < 0) {
			vx *= -1;
		}
		if (y > areaHeight - r && y < 0 || y > areaHeight - r && y > 0 || y < r && y > 0) {
			vy *= -1;
		}
		vy += gravity;
		x += vx * deltaT;
		y += vy * deltaT;
	}

	@Override
	public List<Ellipse2D> getBalls() {
		List<Ellipse2D> myBalls = new LinkedList<Ellipse2D>();
		myBalls.add(new Ellipse2D.Double(x - r, y - r, 2 * r, 2 * r));
		return myBalls;
	}
	
	public Ellipse2D getBallEllipse2D() {
		return new Ellipse2D.Double(x - r, y - r, 2 * r, 2 * r);
	}

	protected double getX() {
		return x;
	}

	protected void setX(double x) {
		this.x = x;
	}

	protected double getY() {
		return y;
	}

	protected void setY(double y) {
		this.y = y;
	}

	protected double getVx() {
		return vx;
	}

	protected void setVx(double vx) {
		this.vx = vx;
	}

	protected double getVy() {
		return vy;
	}

	protected void setVy(double vy) {
		this.vy = vy;
	}

	protected double getR() {
		return r;
	}

	protected void setR(double r) {
		this.r = r;
	}
	
	protected double getMass() {
		return Math.pow(r, 3);
	}
}